package com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class HomeController {

    @Autowired
    private ApplicationContext context;

    @RequestMapping("")
    public String index() {
        return "index";
    }

    @RequestMapping("/list")
    public String listAllControllers() {
        Map<String, Object> beansWithAnnotation = context.getBeansWithAnnotation(Controller.class);
        beansWithAnnotation.forEach((name, obj) -> {
            System.out.println("控制器名字:" + name);
            System.out.println("控制器的类名:" + obj.getClass().getName());
        });

        return "index";
    }


    @RequestMapping("/parent")
    public String getParent() {
        // AnnotationConfigWebApplicationContext context1;
        // context1.setParent(a);

        ApplicationContext parent = context.getParent();
        System.out.println(parent == null ? "没有000000" : "111111");
        return "index";
    }
}
